package com.game.ammo {
	import flash.display.BitmapData;
	import flash.geom.Matrix;
	import flash.display.Shape;
	import flash.geom.Point;
	import flash.filters.BlurFilter;
	import flash.filters.GlowFilter;
	public class AmmoGraphics {
		public function AmmoGraphics() {
			// constructor code
		}
		public static function bullet():BitmapData {
			var shp:Shape = new Shape();
			var bulletSize:int = 20;
			var strip:BitmapData = new BitmapData(bulletSize * (1+(360 / 15)), bulletSize, true, 0);
			shp.graphics.clear();
			shp.graphics.lineStyle(2, 0xffcc00);
			shp.graphics.moveTo(0, 0);
			shp.graphics.lineTo(bulletSize / 3, 0);
			//
			shp.graphics.moveTo(0, 0);
			shp.graphics.lineTo(bulletSize / 8, bulletSize / 8);
			//
			shp.graphics.moveTo(0, 0);
			shp.graphics.lineTo(bulletSize / 8, -bulletSize / 8);
			shp.x = shp.y = bulletSize / 2;
			var matrix:Matrix = new Matrix();
			for (var i:Number = 0; i <= 360; i += 15) {
				matrix.identity();
				matrix.rotate(i * Math.PI / 180);
				matrix.tx = shp.x + (i / 15) * bulletSize;
				matrix.ty = shp.y;
				strip.draw(shp, matrix);
			}
			strip.applyFilter(strip, strip.rect, new Point(), new GlowFilter());
			strip.applyFilter(strip, strip.rect, new Point(), new GlowFilter(0xffffff, 1, 8, 8, 1, 3));
			return strip;
		}
		public static function slow():BitmapData {
			var shp:Shape = new Shape();
			var bulletSize:int = 20;
			var strip:BitmapData = new BitmapData(bulletSize, bulletSize, true, 0);
			shp.graphics.beginFill(0x00ffff);
			shp.graphics.drawCircle(bulletSize / 2, bulletSize / 2, bulletSize / 2 - 5);
			shp.graphics.endFill();
			//
			shp.graphics.beginFill(0x0000ff, 0.3);
			shp.graphics.drawCircle(bulletSize / 2, bulletSize / 2, bulletSize / 2 - 8);
			shp.graphics.endFill();
			//
			strip.draw(shp);
			strip.applyFilter(strip, strip.rect, new Point(), new BlurFilter());
			return strip;
		}
		public static function wave():BitmapData {
			var shp:Shape = new Shape();
			var waveSize:int = 200;
			var strip:BitmapData = new BitmapData(waveSize * 10, waveSize, true, 0);
			var matrix:Matrix = new Matrix();
			for (var j:Number = 0.1; j <= 1; j += 0.1) {
				shp.graphics.clear();
				shp.graphics.lineStyle(3, 0x00FFFF, 1 - j, false, "none");
				shp.graphics.drawCircle(waveSize / 2, waveSize / 2, (waveSize / 2 - 5) * j);
				shp.graphics.endFill();
				matrix.identity();
				matrix.tx = (j - 0.1) * waveSize * 10;
				strip.draw(shp, matrix);
			}
			strip.applyFilter(strip, strip.rect, new Point(), new BlurFilter());
			return strip;
		}
		public static function rocket(bmp:BitmapData):BitmapData {
			var shp:Shape = new Shape();
			var missileSize:int = bmp.width;
			shp.x = shp.y = missileSize / 2;
			shp.graphics.beginBitmapFill(bmp, new Matrix(1, 0, 0, 1, -missileSize / 2, -missileSize / 2), false, true);
			shp.graphics.drawRect(-missileSize / 2, -missileSize / 2, missileSize, missileSize);
			shp.graphics.endFill();
			var strip:BitmapData = new BitmapData(missileSize * (1+(360 / 15)), missileSize, true, 0);
			var matrix:Matrix = new Matrix();
			for (var i:Number = 0; i <= 360; i += 15) {
				matrix.identity();
				matrix.rotate(i * Math.PI / 180);
				matrix.tx = shp.x + (i / 15) * missileSize;
				matrix.ty = shp.y;
				strip.draw(shp, matrix);
			}
			return strip;
		}
		public static function flame(bmp:BitmapData):BitmapData {
			var shp:Shape = new Shape();
			var flameSize:int = bmp.width;
			shp.x = shp.y = flameSize / 2;
			shp.graphics.beginBitmapFill(bmp, new Matrix(1, 0, 0, 1, -flameSize / 2, -flameSize / 2), false, true);
			shp.graphics.drawRect(-flameSize / 2, -flameSize / 2, flameSize, flameSize);
			shp.graphics.endFill();
			//
			var strip:BitmapData = new BitmapData(flameSize * (1+(360 / 15)), flameSize * 10, true, 0);
			var matrix:Matrix = new Matrix();
			for (var i:Number = 0; i <= 360; i += 15) {
				for (var j:Number = 0.1; j <= 1; j += 0.1) {
					matrix.identity();
					matrix.rotate(i * Math.PI / 180);
					matrix.scale(j, j);
					matrix.tx = shp.x + (i / 15) * flameSize;
					matrix.ty = shp.y + (j - 0.1) * flameSize * 10;
					strip.draw(shp, matrix);
				}
			}
			return strip;
		}
		public static function spark():BitmapData {
			var shp:Shape = new Shape();
			var flameSize:int = 100;
			shp.x = shp.y = flameSize / 2;
			var strip:BitmapData = new BitmapData(flameSize * (1+(360 / 15)), flameSize * 10, true, 0);
			var matrix:Matrix = new Matrix();
			for (var i:Number = 0; i <= 360; i += 15) {
				for (var j:Number = 0.1; j <= 1; j += 0.1) {
					matrix.identity();
					shp.graphics.clear();
					shp.graphics.lineStyle(0, 0x00ccff);
					shp.graphics.moveTo(0, 0);
					for (var k:Number = 0; k < 1; k += 0.1) {
						shp.graphics.lineTo(j * (k + (0.5 - Math.random()) / 5) * flameSize / 2, 10 * (0.5 - Math.random()));
					}
					shp.graphics.lineTo(j * flameSize / 2, 0);
					matrix.rotate(i * Math.PI / 180);
					matrix.tx = shp.x + (i / 15) * flameSize;
					matrix.ty = shp.y + (j - 0.1) * flameSize * 10;
					strip.draw(shp, matrix);
				}
			}
			strip.applyFilter(strip, strip.rect, new Point(), new GlowFilter(0x00ccff, 1, 4, 4, 1, 3));
			strip.applyFilter(strip, strip.rect, new Point(), new GlowFilter(0xffffff, 1, 8, 8, 1, 2));
			return strip;
		}
	}
}